# _*_coding:utf-8 _*_
# @Time　　:2021/1/31 14:36
# @Author　 : wangyong
# @File　　  :login.py
# @Software  :PyCharm

from ApiTest.api.base_api import BaseApi
from ApiTest.conf.config import online_host
from ApiTest.utils.log import get_log

log = get_log("login")


class Login(BaseApi):
    headers = {
        "Content-Type": "application/json;charset=UTF-8",
        "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, "
                      "like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 "
    }
    url = online_host+"api/v2/login/byusername"

    def login(self, json):
        try:
            log.info("开始进行登录接口调用，调用URL为：{} 请求参数：{}".format(self.url, json))
            res = self.send_request_session(method="post", url=self.url, json=json, headers=self.headers)
            log.info("返回接口数据为：{}".format(res.json()))
            return res.json()
        except Exception as e:
            log.info("接口出现异常：{}".format(e))
